package com.atguigui.leetcode1;

import java.util.Arrays;

/**
 * 2785. 将字符串中的元音字母排序
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/7/24 16:30
 */
public class P2785SortVowelsInAString {
    public static void main(String[] args) {
        String s = new P2785SortVowelsInAString().sortVowels("lEetcOde");
    }

    public String sortVowels(String s) {
        char[] c = new char[s.length()];
        Integer[] i = new Integer[s.length()];

        Arrays.fill(i, -1);
        Arrays.fill(c, '|');

        int index = 0;
        for (int x = 0; x < s.length(); x++) {
            String str = s.substring(x, x + 1);
            if ("a".equalsIgnoreCase(str) || "e".equalsIgnoreCase(str) || "i".equalsIgnoreCase(str) || "o".equalsIgnoreCase(str) || "u".equalsIgnoreCase(str)) {
                c[index] = str.charAt(0);
                i[index] = x;

                index++;
            }
        }

        Arrays.sort(c);

        char[] charArray = s.toCharArray();

        for (int x = 0; x < i.length; x++) {
            Integer ind = i[x];
            if (ind == -1) {
                break;
            }
            charArray[ind] = c[x];
        }

        return String.valueOf(charArray);


    }
}
